Reconsider constraints involving parameter specifications#15272
Reconsider constraints involving parameter specifications#15272hauntsaninja merged 5 commits intopython:masterfrom
Conversation
This comment has been minimized.
This comment has been minimized.
|
Mypy primer diff looks right! |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Fake error
Decently close to coming up with a reliable way to trigger this logic, but funnily enough I found a paramspec bug 👻 Just marking it here before I forget: from typing import Generic, Callable, Union
from typing_extensions import ParamSpec, Concatenate
P = ParamSpec("P")
P1 = ParamSpec("P1")
class Tester(Generic[P1]):
@staticmethod
def test_something(x: Callable[P, None]) -> Tester[P]: ... # type: ignore[empty-body]
@staticmethod
def test_concatenate(x: Callable[P, None]) -> Tester[Concatenate[int, P]]: ... # type: ignore[empty-body]
def func(
action: Callable[P, None],
) -> None:
job = Tester.test_concatenate(action) if True else Tester.test_something(action)
reveal_type(job)err, actually i'm decently sure that's just inference being annoying :( |
This comment has been minimized.
This comment has been minimized.
| if self.op == SUPERTYPE_OF: | ||
| op_str = ":>" | ||
| return f"{self.type_var} {op_str} {self.target}" | ||
| return f"{self.origin_type_var} {op_str} {self.target}" |
There was a problem hiding this comment.
I'm not too sure why this was this way before and if this is entirely bad behavior. I added this (and updates to hashing and equality) because paramspec types have extra state that is important: their prefix (which Concatenate adds)
|
Diff from mypy_primer, showing the effect of this PR on open source code: discord.py (https://github.com/Rapptz/discord.py)
+ discord/ext/commands/core.py:1729: error: Overloaded function signatures 1 and 2 overlap with incompatible return types [misc]
+ discord/ext/commands/core.py:1799: error: Overloaded function signatures 1 and 2 overlap with incompatible return types [misc]
|
|
Hi, bumping for @hauntsaninja or maybe @JukkaL. |
hauntsaninja
left a comment
There was a problem hiding this comment.
Thanks, looks great! Might be worth a follow up PR to see if we can deduplicate a little bit or factor some stuff out of visit_instance
|
|
||
| # I don't think we can parametrize... | ||
| for direction in (SUPERTYPE_OF, SUBTYPE_OF): | ||
| print(f"direction is {direction}") |
There was a problem hiding this comment.
Oh oops, lol.
Err wait, IIRC that's in order to make any test failures easier to check (it'll only show stdout on test failure).
|
I am going to revert this. IMO this is just a bunch of more hacks to compensate for older hacks. Current |
|
I do think this isn't necessarily hacky -- I basically updated the code directly based on how I expect things to work out.... but I understand that ParamSpec support as a whole is hacky so... Makes sense (I'm still surprised that this solved any issues at all; I made this PR because things were being weird) |
|
Yes, right, this doesn't really adds new hacks. I think I have an idea how to make ParamSpec a bit more principled. I am going to include some part of cleanups in coming inference PR (just because I was touching related code). Then I will make a separate second PR. I see you are interested in this topic. I will keep you posted on Discord. |
Concatenatereturn value #15073Concatenatereturn value #15086Yet another part of #14903 that's finally been extracted!